package lumis.portal.audit;

import java.util.List;

import org.hibernate.criterion.Criterion;

import lumis.portal.PortalException;
import lumis.portal.dao.hibernate.GenericHibernateDao;
import lumis.portal.transaction.PortalTransactionFactory;

/**
 * Data access object for {@link AuditConfig} class.
 *
 * @version $Revision: 13093 $ $Date: 2011-05-28 18:40:18 -0300 (Sat, 28 May 2011) $
 * @since 6.0.0
 */
class AuditConfigDao extends GenericHibernateDao<AuditConfig, String>
{
	protected AuditConfigDao()
	{
		super(AuditConfig.class);
	}	
	
	
	protected AuditConfig findConfiguration() throws PortalException
	{
		// read current configuration
		List<AuditConfig> listAuditConfig = findByCriteria(PortalTransactionFactory.getCurrentTransaction(), (Criterion[]) null);
		
		if (listAuditConfig.isEmpty())
		{
			// persist default configuration
			AuditConfig auditConfig = new AuditConfig();
			persist(auditConfig, PortalTransactionFactory.getCurrentTransaction());
			
			return auditConfig;
		}
		else
		{
			return listAuditConfig.get(0);
		}		
	}	
}